﻿package mortal.game.view.guild.otherpanel
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.resWin.*;
    import mortal.game.cache.*;
    import mortal.game.cache.guild.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.guild.cellrender.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildGodTreePanel extends ResBaseWindow
    {
        private var _bmpTxtSchoolLevel:BitmapNumberText;
        private var _txtSchoolName:GTextFiled;
        private var _bmpBigBuilding:GImageBitmap;
        private var _list:GTileList;
        private var _pageSelecter:PageSelecter;
        private var _buffArray:Vector.<TreeBuff>;
        private static var _instance:GuildGodTreePanel = null;
        private static const PAGE_CELL_COUNT:int = 10;

        public function GuildGodTreePanel(param1:ILayer = null)
        {
            super(param1);
            setSize(732, 503);
            title = "" + Language.getString(71173);
            titleHeight = 60;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(UIFactory.bg(18, 39, 227, 450, this, ImagesConst.guildInfoBg));
            pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.guildLevelBg, 50, 56, this));
            this._bmpTxtSchoolLevel = UIFactory.bitmapNumberText(115, 82, "StrengthenNumber.png", 32, 40, -6, this);
            this._bmpTxtSchoolLevel.text = "24";
            var _loc_1:* = GlobalStyle.textFormatItemGreen;
            _loc_1.align = "center";
            this._txtSchoolName = UIFactory.gTextField("", 58, 152, 150, 24, this, _loc_1);
            this._txtSchoolName.text = GuildConst.getBuildingNameByType(EGuildStructureType._EGuildTree);
            this._bmpBigBuilding = UIFactory.gImageBitmap(ImagesConst.GuildBuilding_Big_1, 25, 277, this);
            pushUIToDisposeVec(UIFactory.bg(250, 37, 470, 450, this));
            this._list = UIFactory.tileList(257, 40, 470, 410, this);
            this._list.rowHeight = 80;
            this._list.columnWidth = 220;
            this._list.setStyle("cellRenderer", GuildGodTreeCellRenderer);
            var _loc_2:* = GlobalStyle.textFormatBai;
            _loc_2.align = "center";
            this._pageSelecter = UIFactory.pageSelecter(400, 460, this, PageSelecter.CompleteMode);
            this._pageSelecter.setbgStlye(ImagesConst.ComboBg, _loc_2);
            this._pageSelecter.maxPage = 3;
            this._pageSelecter.currentPage = 1;
            this._pageSelecter.pageTextBoxSize = 45;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            NetDispatcher.addCmdListener(ServerCommand.BufferUpdate, this.onBufferUpdate);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            NetDispatcher.removeCmdListener(ServerCommand.BufferUpdate, this.onBufferUpdate);
            this._bmpTxtSchoolLevel.dispose(param1);
            this._txtSchoolName.dispose(param1);
            this._bmpBigBuilding.dispose(param1);
            this._list.dispose(param1);
            this._pageSelecter.dispose(param1);
            this._bmpTxtSchoolLevel = null;
            this._txtSchoolName = null;
            this._bmpBigBuilding = null;
            this._list = null;
            this._pageSelecter = null;
            this._buffArray = null;
            return;
        }// end function

        private function onBufferUpdate(param1:Object) : void
        {
            this.refresh();
            return;
        }// end function

        override public function refresh(param1:Boolean = false) : void
        {
            super.refresh(param1);
            if (!allowRefresh)
            {
                return;
            }
            var _loc_2:* = Cache.instance.guild.selfGuildInfo;
            this._bmpTxtSchoolLevel.text = _loc_2.baseInfo.level.toString();
            var _loc_3:* = GuildBuildingConfig.instance.getInfoByBuildingType(_loc_2.baseInfo.level, EGuildStructureType._EGuildSchool).structureLevel;
            var _loc_4:* = GuildSchoolConfig.instance.getInfoByLevel(_loc_3);
            this._pageSelecter.maxPage = this._buffArray.length / PAGE_CELL_COUNT == 0 ? (1) : (Math.ceil(this._buffArray.length / PAGE_CELL_COUNT));
            this.ShowList(this._pageSelecter.currentPage);
            return;
        }// end function

        override protected function loadData() : void
        {
            super.loadData();
            this._buffArray = Cache.instance.guild.CurrentTreeBuff;
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.refresh();
            return;
        }// end function

        private function ShowList(param1:int) : void
        {
            var _loc_2:* = param1;
            var _loc_3:* = (_loc_2 - 1) * PAGE_CELL_COUNT;
            var _loc_4:* = this._buffArray.length;
            var _loc_5:* = new DataProvider();
            var _loc_6:* = _loc_2 * PAGE_CELL_COUNT;
            if (_loc_6 > _loc_4)
            {
                _loc_6 = _loc_4;
            }
            var _loc_7:* = _loc_3;
            while (_loc_7 < _loc_6)
            {
                
                _loc_5.addItem(this._buffArray[_loc_7]);
                _loc_7++;
            }
            this._list.dataProvider = _loc_5;
            this._list.drawNow();
            return;
        }// end function

        public static function get instance() : GuildGodTreePanel
        {
            if (!_instance)
            {
                _instance = new GuildGodTreePanel;
            }
            return _instance;
        }// end function

    }
}
